/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * dishesupdatepanel.java
 *
 * Created on Oct 11, 2010, 11:29:09 AM
 */

package cat20032010;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author acer
 */
public class dishesupdatepanel extends javax.swing.JPanel {
	String str=null;
	String[] temp ;
	String dateString=null;
	String Status = null;
	Statement stmt;
    private ResultSet rset;
    /** Creates new form dishesupdatepanel */
    public dishesupdatepanel() {
        initComponents();
 
    }
    public void clear(){
        jTextField3.setText("");
        jTextField4.setText("");
        jTextField5.setText("");
        jTextField8.setText("");
        jTextField9.setText("");
    }
    public void passing (){
    	str = kitchen_frame.str;
    	
    	temp = str.split("\\,");
    	for(int i =1; i < temp.length ; i++)
    	    temp[i]= removeCharAt(temp[i],0);

    //	for(int i =1; i < temp.length ; i++)
    //		System.out.println(temp[i]);
    	printdata();
    }
    public static String removeCharAt(String s, int pos) {
 	   StringBuffer buf = new StringBuffer( s.length() - 1 );
 	   buf.append( s.substring(0,pos) ).append( s.substring(pos+1) );
 	   return buf.toString();
 	}
    public void printdata(){
    	if (!temp.equals(null)){
    	jTextField3.setText(temp[0]);
    	jTextField4.setText(temp[1]);
    	jTextField5.setText(temp[2]);
    	
    }
    	if (temp[4].equals("PENDING")){
    	   jTextField8.setText(temp[4]);
    	   jTextField9.setText("INPROGRESS");
    	   Status = "INPROGRESS";
    	}
    	   else if (temp[4].equals("INPROGRESS")){
    		   jTextField8.setText(temp[4]);
        	   jTextField9.setText("DONE");
        	   Status = "DONE";
    	   }
    	Date currentDate = new Date();
    	SimpleDateFormat formatter = new SimpleDateFormat("kk:mm:ss");
    	dateString = formatter.format(currentDate);
    	jTextField6.setText(dateString);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        jTextField8 = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        jTextField9 = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dishes Update", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Tahoma", 1, 24))); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(620, 460));
        jPanel1.setLayout(null);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel3.setText("Menu Code         ");
        jPanel1.add(jLabel3);
        jLabel3.setBounds(20, 160, 140, 20);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel4.setText("Menu Name         ");
        jPanel1.add(jLabel4);
        jLabel4.setBounds(20, 210, 143, 20);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel5.setText("Table No.");
        jPanel1.add(jLabel5);
        jLabel5.setBounds(20, 110, 110, 20);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel6.setText("Time");
        jPanel1.add(jLabel6);
        jLabel6.setBounds(20, 260, 80, 20);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel8.setText("Menu Status                ");
        jPanel1.add(jLabel8);
        jLabel8.setBounds(380, 108, 180, 20);

        jLabel20.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel20.setText(":");
        jPanel1.add(jLabel20);
        jLabel20.setBounds(170, 110, 22, 17);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel9.setText("From");
        jPanel1.add(jLabel9);
        jLabel9.setBounds(380, 147, 70, 20);

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel10.setText("To");
        jPanel1.add(jLabel10);
        jLabel10.setBounds(380, 216, 70, 20);

        jLabel21.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel21.setText(":");
        jPanel1.add(jLabel21);
        jLabel21.setBounds(170, 160, 23, 17);

        jLabel22.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel22.setText(":");
        jPanel1.add(jLabel22);
        jLabel22.setBounds(170, 210, 23, 17);

        jLabel23.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel23.setText(":");
        jPanel1.add(jLabel23);
        jLabel23.setBounds(170, 260, 22, 17);

        jButton1.setBorderPainted(false);
        jButton1.setContentAreaFilled(false);
        jPanel1.add(jButton1);
        jButton1.setBounds(470, 347, 33, 9);

        jButton3.setBorderPainted(false);
        jButton3.setContentAreaFilled(false);
        jPanel1.add(jButton3);
        jButton3.setBounds(419, 347, 33, 9);

        jTextField3.setEditable(false);
        jPanel1.add(jTextField3);
        jTextField3.setBounds(200, 110, 141, 20);

        jTextField4.setEditable(false);
        jPanel1.add(jTextField4);
        jTextField4.setBounds(200, 160, 141, 20);

        jTextField5.setEditable(false);
        jPanel1.add(jTextField5);
        jTextField5.setBounds(200, 210, 141, 20);

        jTextField6.setEditable(false);
        jPanel1.add(jTextField6);
        jTextField6.setBounds(200, 260, 141, 20);

        jLabel25.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel25.setText(":");
        jPanel1.add(jLabel25);
        jLabel25.setBounds(461, 149, 22, 17);

        jTextField8.setEditable(false);
        jPanel1.add(jTextField8);
        jTextField8.setBounds(488, 137, 114, 43);

        jLabel26.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel26.setText(":");
        jPanel1.add(jLabel26);
        jLabel26.setBounds(461, 218, 22, 17);

        jTextField9.setEditable(false);
        jPanel1.add(jTextField9);
        jTextField9.setBounds(490, 210, 114, 42);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button/BACK.png"))); // NOI18N
        jButton4.setToolTipText("");
        jButton4.setBorderPainted(false);
        jButton4.setContentAreaFilled(false);
        jButton4.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/button/BACKMouseOver.png"))); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton4);
        jButton4.setBounds(470, 360, 120, 60);
        jPanel1.add(jLabel2);
        jLabel2.setBounds(150, 20, 380, 0);
        jPanel1.add(jLabel1);
        jLabel1.setBounds(0, -110, 670, 0);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button/OK.png"))); // NOI18N
        jButton2.setBorderPainted(false);
        jButton2.setContentAreaFilled(false);
        jButton2.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/button/OKMouseOver.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton2);
        jButton2.setBounds(340, 360, 130, 60);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 644, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 460, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    	int reply = JOptionPane.showConfirmDialog(null, "Confirm Cancel Changing Status?", "Confirm", JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.YES_OPTION){
        	kitchen_frame.dishesupdatepanel.setVisible(false);
        	kitchen_frame.kitchenpanel.setVisible(true);
        	clear();
        	}
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        kitchen_frame.dishesupdatepanel.setVisible(false);
        kitchen_frame.kitchenpanel.setVisible(true);
        try {
            Main.getConnection();
            stmt = Main.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
            System.out.println(temp[5]);
            String SQL = "Update Order_List set KITCHEN_STATUS = '"+Status+"',TIME_PROCEED = '"+dateString+"' where Menu_Code = '"+temp[1]+"' and Menu_Name = '"+temp[2]+"' and Table_Num = '"+temp[0]+"' and Time_Order = '"+temp[5]+"'";
            System.out.println(SQL);
            rset = stmt.executeQuery(SQL);
    //        System.out.println(SQL);
            
            JOptionPane.showMessageDialog(null, "Status Updated!", "Success!", JOptionPane.INFORMATION_MESSAGE);
        }catch (SQLException e) {
        JOptionPane.showMessageDialog(null, "Unable to Update!", "Error!", JOptionPane.ERROR_MESSAGE);
        }
        clear();
    }//GEN-LAST:event_jButton2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    // End of variables declaration//GEN-END:variables

}
